package cn.itsource.basic.common;

import cn.itsource.basic.domain.AjaxResult;
import cn.itsource.basic.util.PhoneUtil;
import cn.itsource.basic.util.RedisService;
import cn.itsource.org.domain.Shop;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("verification")
@Api(value = "图片上传管理接口",description = "图片上传管理接口")
public class PhoneController {

    @Autowired
    RedisService redisService;

    @PostMapping("sendBinderVerificationCode")
    public AjaxResult phoneFile(@RequestBody  String phone){
        if(redisService.getKeyObjectValue(phone, StringBuilder.class) == null) {
            StringBuilder code = new StringBuilder();
            for (int i = 0; i < 5; i++) {
                int i1 = (int) Math.random() * 10;
                code.append(i1);
            }
            PhoneUtil.email1(phone, code);
            redisService.setStringKeyAndValue(phone, code, 1);
            return AjaxResult.me();
        }else{
            return AjaxResult.setMsg("一分钟以内不能连续发送多次");
        }
    }
}
